<?php
class Custom 
{  
  public function __construct($connection) {
    $this->Connection = $connection;
  }
  
  public function GetAllCustom() {
    $custom = array();
    $queries = new mysqlqueries();
    $result = $this->Connection->query($queries->GetTable($queries->Customqueries, "query"));
    while ($row = mysqli_fetch_array($result)) {
      array_push($custom, array($row["ID"],$row["query"],$row["type"]));
    }
    return $custom;
  }
  
  public function AddQueries($customs) {
    $args = array();
    foreach ($customs as $custom) {
      if($custom[0] != "" && is_numeric($custom[1]) && $custom[1]>0 && $custom[0]<=3)
      {
        $type = "";
        switch ($custom[1]) {
          case 1:
            $type = "Device";
            break;
          case 2:
            $type = "PC";
            break;
          case 3:
            $type = "Printer";
            break;
        }
        array_push($args, array($custom[0],$type));
      }
    }
    if(count($args)>0)
    {
      $queries = new mysqlqueries();
      $query=$queries->Add($queries->Customqueries, $args);
      $this->Connection->query($query);
      return true;
    }
    return false;
  }
  
  public function RemoveCustom($id) {
    $queries = new mysqlqueries();
    $query = $queries->Remove($queries->Customqueries, NULL, $id);
    if(!$query)
    {
      return false;
    }
    $this->Connection->query($query);
    return true;
  }
  
  public $Connection;
}

